from flask import Blueprint
from common.libs.utils.json_response import JsonResponse
route_test = Blueprint('test_page', __name__)
import logging
from flask_jwt_extended import create_access_token, get_jwt_identity
from flask_jwt_extended import jwt_required

"""
测试controller
"""

logger = logging.getLogger(__name__)

@route_test.route("/testLogtestLog")
def test():
    """
    这个方法用来测试日志
    """
    logger.info("asdlfjasldkfjalsdkjfalsdjf")
    return JsonResponse.success(123/0)

@route_test.route("/login")
def login():
    """
    测试登录
    """
    user_id = 123
    access_token = create_access_token(identity=user_id)
    return JsonResponse.success(access_token)

@route_test.route("/checkLogin")
@jwt_required()
def check_login():
    """
    校验登录
    """
    user_id = get_jwt_identity()
    return JsonResponse.success(user_id)


# @route_test.before_request
# def before():
#
#     print(request)
#     return JsonResponse.error(500, "你还没登录")